from models import db

class Timetable(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80),nullable=False)
    description = db.Column(db.String(200))
    starttime = db.Column(db.DateTime,nullable=False)
    endtime = db.Column(db.DateTime,nullable=False)
    clockins = db.relationship('Clockin',backref='Timetable',lazy=True)
    
    def __init__(self, dic):
        for key,value in dic.items():
            setattr(self, key, value)

    def __repr__(self):
        return '{}:{}:{}'.format(self.name,self.starttime,self.endtime)


tags = db.Table(
        'timetabletags',
        db.Column('timetable_id',db.Integer, db.ForeignKey('timetable.id')),
        db.Column('tag_id',db.Integer, db.ForeignKey('tag.id'))
)
